<?php

namespace App\Manage;


use App\Models\SiteVersion;
use App\Models\SiteCate;

class SiteVersionManage extends Manage
{
    // 版本

    // 父级
    // 添加，修改，删除，列表，停用 操作


    // 返回列表数据
    public function lists($myUser, $options = [])
    {

        $opt      = $this->option();
        $platform = $opt->getData('platform', null, 'trim');
        $code     = $opt->getData('code', null, 'trim');
        $name     = $opt->getData('name', null, 'trim');
        $page     = $opt->getData('page', 1, 'intval');
        $rows     = $opt->getData('rows', 15, 'intval');

        // 条件
        $where = $map = [];
        if($platform){
            $map['platform'] = $platform;
            $where[]         = ['platform', '=', $platform];
        }
        if($code){
            $map['code'] = $code;
            $where[]     = ['code', '=', $code];
        }
        if($name){
            $map['name'] = $name;
            $where[]     = ['name', '=', $name];
        }

        // 缓存
        $model  = new SiteVersion();
        $isBang = $model->bangData($map);
        if($isBang === false){
            return $this->_returnFail($model->getError());
        }

        // 执行
        $result = $model->listPage($where, $page, $rows, "id DESC");


        return $result;
    }

    // 添加
    protected function _before_add()
    {


        // 参数
        $is_admin_log = $options['is_admin_log'] ?? 0;


        $opt  = $this->option();
        $data = [
            'platform' => $opt->getData("platform", null, 'trim'),
            'code'     => $opt->getData("code", null, 'trim'),
            'name'     => $opt->getData("name", null, 'trim'),
            'url'      => $opt->getData("url", null, 'trim'),
            'remark'   => $opt->getData("remark", null, 'trim'),
            //'ctime'    => $opt->getData("ctime", null, 'trim'),
            //'mtime'    => $opt->getData("mtime", null, 'trim'),
        ];


        // 管理员日志
        /*if($is_admin_log){
            $this->addAdminLog($myUser['id'], '修改自己的个人资料', '');
        }*/


        return $data;
    }

    // 修改
    protected function _before_edit()
    {


        // 参数
        $is_admin_log = $options['is_admin_log'] ?? 0;


        $opt  = $this->option();
        $data = [
            'platform' => $opt->getData("platform", null, 'trim'),
            'code'     => $opt->getData("code", null, 'trim'),
            'name'     => $opt->getData("name", null, 'trim'),
            'url'      => $opt->getData("url", null, 'trim'),
            'remark'   => $opt->getData("remark", null, 'trim'),
            //'ctime'    => $opt->getData("ctime", null, 'trim'),
            //'mtime'    => $opt->getData("mtime", null, 'trim'),
        ];


        // 管理员日志
        /*if($is_admin_log){
            $this->addAdminLog($myUser['id'], '修改自己的个人资料', '');
        }*/


        return $data;
    }

}


